#include <stdlib.h>
#include <stdio.h>
#include "md5.h"
#include "generation_cle.h"

void generate_key(FILE *file, unsigned long size_file, int nb_pieces, int taille_pieces, md5_byte_t digest[16])
{
  md5_state_t state;
  md5_byte_t *buf = malloc(sizeof(char)*(taille_pieces));
  
  md5_init(&state);
  int tmp = size_file;
  while (tmp > 0)
    { 
      if (tmp < taille_pieces)
	taille_pieces = tmp;
      fread(buf, sizeof(char), taille_pieces, file); 
      md5_append(&state, buf, taille_pieces);
      tmp -= taille_pieces;
    }
  md5_finish(&state, digest);

  free(buf);
}
